﻿Imports System.Windows.Forms.Form
Imports System.String


Public Class MainActivity

    Dim blnIsLocked As Boolean = False
    Dim strBuffers(12) As String
    Dim myBuildInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Application.ExecutablePath)


    Private Sub chkLock_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkLock.CheckedChanged
        If chkLock.Checked = True Then
            blnIsLocked = True
        End If
        If chkLock.Checked = False Then
            blnIsLocked = False
        End If
    End Sub

    Private Sub chkAlwaysOnTop_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkAlwaysOnTop.CheckedChanged
        If chkAlwaysOnTop.Checked = True Then
            Me.TopMost = True
        End If
        If chkAlwaysOnTop.Checked = False Then
            Me.TopMost = False
        End If
    End Sub

    Private Sub MainActivity_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If cmbButtonsVisible.SelectedItem = Nothing Then
            My.Settings.DefaultButtons = "5"
        Else
            My.Settings.DefaultButtons = cmbButtonsVisible.SelectedText
        End If
        My.Settings.Locked = chkLock.CheckState
        My.Settings.AlwaysOnTop = chkAlwaysOnTop.CheckState
        My.Settings.BufferOne = strBuffers(1)
        My.Settings.BufferTwo = strBuffers(2)
        My.Settings.BufferThree = strBuffers(3)
        My.Settings.BufferFour = strBuffers(4)
        My.Settings.BufferFive = strBuffers(5)
        My.Settings.BufferSix = strBuffers(6)
        My.Settings.BufferSeven = strBuffers(7)
        My.Settings.BufferEight = strBuffers(8)
        My.Settings.BufferNine = strBuffers(9)
        My.Settings.BufferTen = strBuffers(10)
        My.Settings.BufferEleven = strBuffers(11)
    End Sub

    Private Sub MainActivity_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        If My.Settings.DefaultButtons = "3" Then
            cmbButtonsVisible.SelectedIndex = 0
            ChangeSize3()
            Application.DoEvents()
        End If
        If My.Settings.DefaultButtons = "5" Then
            cmbButtonsVisible.SelectedIndex = 1
            ChangeSize5()
            Application.DoEvents()
        End If
        If My.Settings.DefaultButtons = "7" Then
            cmbButtonsVisible.SelectedIndex = 2
            ChangeSize7()
            Application.DoEvents()
        End If
        If My.Settings.DefaultButtons = "9" Then
            cmbButtonsVisible.SelectedIndex = 3
            ChangeSize9()
            Application.DoEvents()
        End If
        If My.Settings.DefaultButtons = "11" Then
            cmbButtonsVisible.SelectedIndex = 4
            ChangeSize11()
            Application.DoEvents()
        End If

        strBuffers(1) = My.Settings.BufferOne
        ChangeButtonLabel(1)
        strBuffers(2) = My.Settings.BufferTwo
        ChangeButtonLabel(2)
        strBuffers(3) = My.Settings.BufferThree
        ChangeButtonLabel(3)
        strBuffers(4) = My.Settings.BufferFour
        ChangeButtonLabel(4)
        strBuffers(5) = My.Settings.BufferFive
        ChangeButtonLabel(5)
        strBuffers(6) = My.Settings.BufferSix
        ChangeButtonLabel(6)
        strBuffers(7) = My.Settings.BufferSeven
        ChangeButtonLabel(7)
        strBuffers(8) = My.Settings.BufferEight
        ChangeButtonLabel(8)
        strBuffers(9) = My.Settings.BufferNine
        ChangeButtonLabel(9)
        strBuffers(10) = My.Settings.BufferTen
        ChangeButtonLabel(10)
        strBuffers(11) = My.Settings.BufferEleven
        ChangeButtonLabel(11)
        blnIsLocked = My.Settings.Locked
        If My.Settings.Locked = True Then
            blnIsLocked = True
            chkLock.Checked = True
        End If
        If My.Settings.Locked = False Then
            blnIsLocked = False
            chkLock.Checked = False
        End If
        If My.Settings.AlwaysOnTop = True Then
            Me.TopMost = True
            chkAlwaysOnTop.Checked = True
        End If
        If My.Settings.AlwaysOnTop = False Then
            Me.TopMost = False
            chkAlwaysOnTop.Checked = False
        End If
        'SetButtons()
    End Sub

    Private Sub SetButtons()
        If My.Settings.DefaultButtons = "3" Then
            ChangeSize3()
        End If
        If My.Settings.DefaultButtons = "5" Then
            ChangeSize5()
        End If
        If My.Settings.DefaultButtons = "7" Then
            ChangeSize7()
        End If
        If My.Settings.DefaultButtons = "9" Then
            ChangeSize9()
        End If
        If My.Settings.DefaultButtons = "11" Then
            ChangeSize11()
        End If
    End Sub

    Private Sub cmbButtonsVisible_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbButtonsVisible.SelectedIndexChanged
        If blnIsLocked = False Then
            If cmbButtonsVisible.SelectedIndex = 0 Then
                ChangeSize3()
            End If
            If cmbButtonsVisible.SelectedIndex = 1 Then
                ChangeSize5()
            End If
            If cmbButtonsVisible.SelectedIndex = 2 Then
                ChangeSize7()
            End If
            If cmbButtonsVisible.SelectedIndex = 3 Then
                ChangeSize9()
            End If
            If cmbButtonsVisible.SelectedIndex = 4 Then
                ChangeSize11()
            End If
        End If
    End Sub

    Private Sub ChangeSize3()
        Me.Height = 131
        btnOne.Visible = True
        btnTwo.Visible = True
        btnThree.Visible = True
        btnFour.Visible = False
        btnFive.Visible = False
        btnSix.Visible = False
        btnSeven.Visible = False
        btnEight.Visible = False
        btnNine.Visible = False
        btnTen.Visible = False
        btnEleven.Visible = False
    End Sub

    Private Sub ChangeSize5()
        Me.Height = 171
        btnOne.Visible = True
        btnTwo.Visible = True
        btnThree.Visible = True
        btnFour.Visible = True
        btnFive.Visible = True
        btnSix.Visible = False
        btnSeven.Visible = False
        btnEight.Visible = False
        btnNine.Visible = False
        btnTen.Visible = False
        btnEleven.Visible = False
    End Sub

    Private Sub ChangeSize7()
        Me.Height = 212
        btnOne.Visible = True
        btnTwo.Visible = True
        btnThree.Visible = True
        btnFour.Visible = True
        btnFive.Visible = True
        btnSix.Visible = True
        btnSeven.Visible = True
        btnEight.Visible = False
        btnNine.Visible = False
        btnTen.Visible = False
        btnEleven.Visible = False
    End Sub

    Private Sub ChangeSize9()
        Me.Height = 252
        btnOne.Visible = True
        btnTwo.Visible = True
        btnThree.Visible = True
        btnFour.Visible = True
        btnFive.Visible = True
        btnSix.Visible = True
        btnSeven.Visible = True
        btnEight.Visible = True
        btnNine.Visible = True
        btnTen.Visible = False
        btnEleven.Visible = False
    End Sub

    Private Sub ChangeSize11()
        Me.Height = 289
        btnOne.Visible = True
        btnTwo.Visible = True
        btnThree.Visible = True
        btnFour.Visible = True
        btnFive.Visible = True
        btnSix.Visible = True
        btnSeven.Visible = True
        btnEight.Visible = True
        btnNine.Visible = True
        btnTen.Visible = True
        btnEleven.Visible = True
    End Sub

    Private Sub btnOne_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnOne.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(1) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(1)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(1))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(1) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(1)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnTwo_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnTwo.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(2) = My.Computer.Clipboard.GetText
            ChangeButtonLabel(2)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(2))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(2) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(2)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnThree_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnThree.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(3) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(3)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(3))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(3) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(3)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnFour_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnFour.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(4) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(4)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(4))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(4) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(4)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnFive_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnFive.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(5) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(5)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(5))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(5) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(5)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnSix_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnSix.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(6) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(6)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(6))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(6) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(6)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnSeven_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnSeven.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(7) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(7)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(7))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(7) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(7)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnEight_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnEight.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(8) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(8)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(8))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(8) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(8)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnNine_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnNine.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(9) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(9)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(9))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(9) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(9)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnTen_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnTen.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(10) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(10)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(10))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(10) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(10)
            Application.DoEvents()
        End If
    End Sub

    Private Sub btnEleven_Click(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles btnEleven.MouseDown
        If (e.Button = Windows.Forms.MouseButtons.Right) And blnIsLocked = False Then
            strBuffers(11) = My.Computer.Clipboard.GetText()
            ChangeButtonLabel(11)
            Application.DoEvents()
        ElseIf (e.Button = Windows.Forms.MouseButtons.Left) Then
            My.Computer.Clipboard.SetText(strBuffers(11))
        ElseIf (e.Button = Windows.Forms.MouseButtons.Middle) And blnIsLocked = False Then
            strBuffers(11) = "Buffer" + Environment.NewLine + "Cleared"
            ChangeButtonLabel(11)
            Application.DoEvents()
        End If
    End Sub

    Private Sub ChangeButtonLabel(ByVal i As Integer)
        Dim this As String = GetBufferHeader(strBuffers(i))
        Select Case i
            Case 1
                btnOne.Text = this
            Case 2
                btnTwo.Text = this
            Case 3
                btnThree.Text = this
            Case 4
                btnFour.Text = this
            Case 5
                btnFive.Text = this
            Case 6
                btnSix.Text = this
            Case 7
                btnSeven.Text = this
            Case 8
                btnEight.Text = this
            Case 9
                btnNine.Text = this
            Case 10
                btnTen.Text = this
            Case 11
                btnEleven.Text = this
        End Select

    End Sub

    Private Function GetBufferHeader(ByVal this As String)
        If this <> Nothing Then
            If (InStr(this, Environment.NewLine)) > 0 Then
                Return ((Mid(this, 1, 20)) + Environment.NewLine + Mid(this, (InStr(this, Environment.NewLine)) + 1, 20))
            ElseIf (InStr(this, Environment.NewLine)) <= 0 Then
                Return ((Mid(this, 1, 20)))
            End If
        Else
            Return ("Buffer" + Environment.NewLine + "Cleared")
        End If
    End Function

    Private Sub MainActivity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.F1 Then
            MessageBox.Show("Version " + myBuildInfo.FileVersion + " by " + myBuildInfo.CompanyName + Environment.NewLine + Environment.NewLine +
                            "For more information, please visit http://rubberstamp.azurewebsites.net/" + Environment.NewLine +
                            "View/download source at " + "https://code.google.com/p/rubberstamp/" + Environment.NewLine +
                            "Licensed under GPL v3",
                            "Rubber Stamp - About/Help", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End If
    End Sub
End Class